/**
 * Project Name:MybatisDemo
 * File Name:MyBatisUntil.java
 * Package Name:com.java.untils
 * Date:2018年5月4日下午2:58:48
 * Copyright (c) 2018, bluemobi All Rights Reserved.
 */

package com.sc.mapper;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * Description: <br/>
 * Date: 2018年5月4日 下午2:58:48 <br/>
 * 
 * @author pengchengwang
 * @version
 * @see
 */
public class MyBatisUntil {
    private static SqlSession session = null;

    private static InputStream inputStream = null;
    static {
        SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder();
        try {
            inputStream = Resources.getResourceAsStream("mybatis.xml");
        } catch (IOException e) {

            // Auto-generated catch block
            e.printStackTrace();

        }
        SqlSessionFactory ssf = ssfb.build(inputStream);
        session = ssf.openSession();
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                inputStream = null;
                // Auto-generated catch block
                e.printStackTrace();

            }
        }
    }

    public static SqlSession getSqlSession() {
        return session;
    }

}
